import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/* Layout 主框架 */
import HomeLayout from '@/views/layout/Layout'
/* Router Modules 路由模块 */
import userRouter from './modules/user'

export const constantRoutes = [{
    path: '/redirect',
    component: HomeLayout,
    hidden: true,
    children: [{
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
    }]
},
{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
},
{
    path: '/loginlocal',
    component: () => import('@/views/login/index'),
    hidden: true
},
{
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
},
{
    path: '/error',
    component: () => import('@/views/error'),
    hidden: true
},
{
    path: '/systemauth',
    component: () => import('@/views/systemauth'),
    hidden: true
},
{
    path: '/initpsw',
    component: () => import('@/views/initpsw'),
    meta: {
        Auth: "login"
    },
    hidden: true
},
{
    path: '',
    name: '系统框架',
    component: HomeLayout,
    redirect: 'home',
    iconCls: 'el-icon-message',
    meta: {
        Auth: "login"
    },
    children: [{
        path: 'home',
        component: () => import('@/views/home/index'),
        name: 'home',
        meta: {
            title: '工作台',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },

    {
        path: 'banned',
        component: () => import('@/views/banned'),
        meta: {
            title: '服务监管',
            icon: 'el-icon-message',
            Auth: "login",
            hidden: true
        }
    },
    {
        path: 'platform',
        component: () => import('@/views/home/platform'),
        name: 'platform',
        meta: {
            title: '管理平台',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'servicesCatalogue',
        component: () => import('@/views/application/services/catalogue/index'),
        name: 'ChooseRoom',
        meta: {
            title: '服务监督录单',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },

    {
        path: 'repairCatalogue',
        component: () => import('@/views/application/repair/catalogue/home/index'),
        name: 'RepairCatalogue',
        meta: {
            title: '报修录单',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'microMarket',
        component: () => import('@/views/application/micro/microMarket'),
        name: 'MicroMarket',
        meta: {
            title: '二手市场',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'microLost',
        component: () => import('@/views/application/micro/microLost'),
        name: 'MicroLost',
        meta: {
            title: '失物招领',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'applyRoom',
        component: () => import('@/views/application/applyRoom/applyIndex'),
        name: 'ApplyRoom',
        meta: {
            title: '住房申请',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'applyOffice',
        component: () => import('@/views/application/office/applyIndexNew'),
        name: 'ApplyRoom',
        meta: {
            title: '办公用房申请',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'chooseRoom',
        component: () => import('@/views/home/chooseRoom'),
        name: 'ChooseRoom',
        meta: {
            title: '选房申请',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'transactionCenter',
        component: () => import('@/views/home/transactionCenter'),
        name: 'TransactionCenter',
        meta: {
            title: '事务中心',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'messageCenter',
        component: () => import('@/views/home/messageCenter'),
        name: 'MessageCenter',
        meta: {
            title: '消息中心',
            icon: 'el-icon-message',
            Auth: "login"
        }
    },
    {
        path: 'applicationCenter',
        component: () => import('@/views/home/applicationCenter'),
        name: 'ApplicationCenter',
        meta: {
            title: '应用中心',
            icon: 'el-icon-message',
            Auth: "login"
        }
    }
    ]
},
    userRouter
    //{path: '*', redirect: '/404', hidden: true}
]
const createRouter = () => new Router({
    mode: 'history', // require service support
    base: '/account/',
    code: 'account',
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes
})
const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
};
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}
export default router